<script setup lang="ts">
import {markRaw, onMounted, ref} from "vue";
import type {EChartsOption, EChartsType} from "echarts";
import * as echarts from "echarts";
import {useGetLineDataApi} from "@/api";
import type {Line} from "@/interface";
import 'echarts-wordcloud'

const line = ref()
const option = ref<EChartsOption>()
const myChart = ref<EChartsType>()
const lineData = ref<Line>({
  name:[],
  value:[]
})
const init = async () => {
  const {data:res} = await useGetLineDataApi()
  lineData.value = res
  myChart.value = markRaw(echarts.init(line.value));
  draw();
}
const draw = () => {
  option.value = {
    title:{
      text:'小说更新时间趋势',
      left:'center'
    },
    tooltip:{},
    xAxis: {
      type: 'category',
      data: lineData.value.name
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: lineData.value.value,
        type: 'line'
      }
    ]
  }
  myChart.value.setOption(option.value, {notMerge: true});
}
onMounted(() => {
  init()
})
</script>

<template>
  <div ref="line" class="line">
  </div>
</template>

<style scoped>
.line{
  width: 100%;
  height: 100%;
}
</style>